<template>
  <div class="container">
    <div class="btn" v-for="(item, index) in list" :key="index" @click="click(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    list: Array,
  },
  data() {
    return {
      divList: null,
    };
  },
  mounted() {
    this.divList = document.getElementsByClassName("btn");
    this.divList[0].className = "btn selected";
  },
  methods: {
    click(index) {
      for (let i = 0; i < this.divList.length; i++) {
        this.divList[i].classList = "btn";
      }
      this.divList[index].className = "btn selected";

      this.$emit("changeParentIndex", index);
    },
  },
};
</script>
<style scoped>
* {
  padding: 0;
  margin: 0;
}
.container {
  width: 750rpx;
  text-align: center;
  padding-top: 20rpx;
  padding-bottom: 20rpx;
  background-color: rgb(247, 248, 248);
  display: flex;
  justify-content: space-around;
}
.btn {
  display: inline-block;
  text-align: center;
  flex: 1;
  font-weight: 500;
}
.selected {
  border-bottom: 1rpx solid #d81e06;
  color: #d81e06;
  font-weight: 700;
}
</style>
